package com.example.foobar.dao.service.impl;

import com.example.foobar.entity.DyComment;
import com.example.foobar.mapper.DyCommentMapper;
import com.example.foobar.dao.service.DyCommentDaoService;
import com.example.foobar.param.DyCommentPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.foobar.vo.DyCommentQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 抖音文字评论 服务实现类
 *
 * @author 郑英奔
 * @since 2021-07-23
 */
@Slf4j
@Service
public class DyCommentDaoServiceImpl extends BaseServiceImpl<DyCommentMapper, DyComment> implements DyCommentDaoService {

    @Autowired
    private DyCommentMapper dyCommentMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDyComment(DyComment dyComment)  {
        return super.save(dyComment);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDyComment(DyComment dyComment)  {
        return super.updateById(dyComment);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDyComment(Long id)  {
        return super.removeById(id);
    }

    @Override
    public Paging<DyCommentQueryVo> getDyCommentPageList(DyCommentPageParam dyCommentPageParam)  {
        Page<DyComment> page = new PageInfo<>(dyCommentPageParam, OrderItem.desc(getLambdaColumn(DyComment::getCreateTime)));
        IPage<DyCommentQueryVo> iPage = dyCommentMapper.getDyVideoPageList(page, dyCommentPageParam);
        return new Paging<>(iPage);
    }

}
